package com.synjones.handsetS8L;

import android.util.Log;



public class util_debug{

	
	private static final String TAG="SynjonesHandset";
	public static boolean DebugSwitch=false;
	public static  void DebugLog(String err){
		if(!DebugSwitch) return;
		Log.e(TAG, err);
	}


	public static byte[] hexString2bytes(String src){
		try{
			if(src==null||src.length()==0) return null;
			int srcLen=src.length();
			if(srcLen%2!=0) {
				src += "0";
				srcLen++;
			}
			byte ret[]=new byte[srcLen/2];
			for(int i=0,j=0;i<=srcLen-2;i+=2,j++){
				String hex=src.substring(i,i+2);
				ret[j]=(byte)Integer.parseInt(hex,16);
			}
			return ret;
		}catch (Exception e){
			e.printStackTrace();
		}
		return null;
	}



	//byte数据转换成string显示出来 比如byte数据12，转换为"12"
		public static String bytesToHexString(byte[] src){  
		    StringBuilder stringBuilder = new StringBuilder("");  
		    if (src == null || src.length <= 0) {  
		        return null;  
		    }  
		    for (int i = 0; i < src.length; i++) {  
		        int v = src[i] & 0xFF;  
		        String hv = Integer.toHexString(v);  
		        stringBuilder.append("0x");
		        if (hv.length() < 2) {  
		            stringBuilder.append(0);  
		        }  
		        
		        stringBuilder.append(hv.toUpperCase());  
		        stringBuilder.append(",");
		    }  
		    return stringBuilder.toString();  
		}
		
		public static String bytesToHexString(byte[] src,int len){  
		    StringBuilder stringBuilder = new StringBuilder("");  
		    if (src == null || src.length <= 0||src.length<len) {  
		        return null;  
		    }  
		    for (int i = 0; i < len; i++) {  
		        int v = src[i] & 0xFF;  
		        String hv = Integer.toHexString(v);  
		        stringBuilder.append("0x");
		        if (hv.length() < 2) {  
		            stringBuilder.append(0);  
		        }  
		        
		        stringBuilder.append(hv.toUpperCase());  
		        stringBuilder.append(",");
		    }  
		    return stringBuilder.toString();  
		}
		
		public static String bytesToHexStringNo0x(byte[] src){  
		    StringBuilder stringBuilder = new StringBuilder("");  
		    if (src == null || src.length <= 0) {  
		        return null;  
		    }  
		    for (int i = 0; i < src.length; i++) {  
		        int v = src[i] & 0xFF;  
		        String hv = Integer.toHexString(v);  
		        
		        if (hv.length() < 2) {  
		            stringBuilder.append(0);  
		        }  
		        
		        stringBuilder.append(hv.toUpperCase());  
		       // stringBuilder.append(" ");
		    }  
		    return stringBuilder.toString();  
		}
		
	
		
}